# import requests
from lxml import etree

# https://p6.qhimg.com/dmfd/180_240_75/d/dy_b3ea38d7eaf544fb178cd4bc98fc537d..webp


# url = "https://www.360kan.com/rank/general"

# url = "https://api.web.360kan.com/v1/rank?cat=1&callback=__jp0"
#
# res = requests.get(url)
#
# print(res.text)



# import asyncio
# import aiohttp
#
# async def fetch(session, url):
#     async with session.get(url) as response:
#         response =  await response.text()
#         print(response[7:-2])
#
# async def main():
#     async with aiohttp.ClientSession() as session:
#         # callback 删掉就可以转成json
#         urls = [f'https://api.web.360kan.com/v1/rank?cat={page}&callback=__jp3{page}' for page in range(1,7)]
#         tasks = [fetch(session, url) for url in urls]
#         await asyncio.gather(*tasks)
#
#
#
# asyncio.run(main())



# import asyncio
# import aiohttp
#
# async def fetch(session, url):
#     async with session.get(url) as response:
#         response =  await response.json()
#         print(response)
#
# async def main():
#     async with aiohttp.ClientSession() as session:
#         # callback 删掉就可以转成json
#         urls = [f'https://api.web.360kan.com/v1/rank?cat={page}' for page in range(1,7)]
#         tasks = [fetch(session, url) for url in urls]
#         await asyncio.gather(*tasks)
#
#
#
# asyncio.run(main())


# 多线程

import threading
import time
import requests

def t_main(url):
    res = requests.get(url)
    print(f'线程{threading.current_thread().name}获取到数据',res.json())
    time.sleep(1)




def main():

    urls = [f'https://api.web.360kan.com/v1/rank?cat={page}' for page in range(1, 7)]
    threads = []
    for url in urls:
        t = threading.Thread(target=t_main,name=f'thread-{url}',args=(url,))
        threads.append(t)
        t.start()
    for t in threads:
        t.join()#阻塞子线程，当所有子线程执行完毕休眠1s然后主线程打印主线程结束了

    print(f"主线程结束了")


if __name__ == '__main__':
    main()




